package vip.xiaonuo.supplier.modular.warehouse.stocks.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fhs.trans.service.impl.TransService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
import vip.xiaonuo.common.enums.CommonSortOrderEnum;
import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.page.CommonPageRequest;
import vip.xiaonuo.common.util.CommonDownloadUtil;
import vip.xiaonuo.common.util.CommonResponseUtil;
import vip.xiaonuo.supplier.modular.base.categories.entity.SupplierCategories;
import vip.xiaonuo.supplier.modular.base.categories.service.SupplierCategoriesService;
import vip.xiaonuo.supplier.modular.base.productions.entity.SupplierProductions;
import vip.xiaonuo.supplier.modular.base.productions.param.SupplierProductionsPageParam;
import vip.xiaonuo.supplier.modular.base.productions.service.SupplierProductionsService;
import vip.xiaonuo.supplier.modular.warehouse.stocks.entity.SupplierStocks;
import vip.xiaonuo.supplier.modular.warehouse.stocks.mapper.SupplierStocksMapper;
import vip.xiaonuo.supplier.modular.warehouse.stocks.param.*;
import vip.xiaonuo.supplier.modular.warehouse.stocks.result.SupplierStocksExportResult;
import vip.xiaonuo.supplier.modular.warehouse.stocks.service.SupplierStocksService;

import java.io.File;
import java.io.IOException;
import java.io.ObjectInput;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
 * 库存明细Service接口实现类
 *
 * @author Mr.wu
 * @date  2025/03/18 14:28
 **/
@Service
public class SupplierStocksServiceImpl extends ServiceImpl<SupplierStocksMapper, SupplierStocks> implements SupplierStocksService {

    @Resource
    private SupplierProductionsService supplierProductionsService;
    @Resource
    private SupplierCategoriesService supplierCategoriesService;
    @Resource
    private TransService transService;
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    @Override
    public Page<SupplierStocks> page(SupplierStocksPageParam supplierStocksPageParam) {
        QueryWrapper<SupplierStocks> queryWrapper = new QueryWrapper<SupplierStocks>().checkSqlInjection();
        //门店或仓库ID
        if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getStockStoreId())) {
            queryWrapper.lambda().and(i -> i.eq(SupplierStocks::getStockStoreId, supplierStocksPageParam.getStockStoreId())
                    .or().eq(SupplierStocks::getStockStorageId, supplierStocksPageParam.getStockStoreId()));
        }
        if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getStockProductionId())){
            queryWrapper.lambda().eq(SupplierStocks::getStockProductionId, supplierStocksPageParam.getStockProductionId());
        }
        //产品名称，拼音，条码，编号
        if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getStockProductionSearchKey())) {
            List<String> ids = CollStreamUtil.toList(supplierProductionsService.list(new QueryWrapper<SupplierProductions>().select("ID").lambda().eq(SupplierProductions::getCompanyId,StpLoginUserUtil.getLoginUser().getCompanyId()).and(i->i.like(SupplierProductions::getProductionName,supplierStocksPageParam.getStockProductionSearchKey())
                    .or().like(SupplierProductions::getProductionPinyincode,supplierStocksPageParam.getStockProductionSearchKey())
                    .or().like(SupplierProductions::getProductionCode,supplierStocksPageParam.getStockProductionSearchKey())
                    .or().like(SupplierProductions::getProductionBarcode,supplierStocksPageParam.getStockProductionSearchKey()))), SupplierProductions::getId);
            if(ObjectUtil.isNotEmpty(ids)) {
                queryWrapper.lambda().in(SupplierStocks::getStockProductionId,ids);
            }else{
                return new Page<>();
            }
        }
        //分类及子分类
        if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getStockProductionCategories())) {
            List<String> childCategoriesIdList = CollStreamUtil.toList(supplierCategoriesService.getChildListById(supplierCategoriesService.getAllCategoriesList(),supplierStocksPageParam.getStockProductionCategories(),true), SupplierCategories::getId);
            if(ObjectUtil.isNotEmpty(childCategoriesIdList)) {
                List<String> productionIds = CollStreamUtil.toList(supplierProductionsService.list(new QueryWrapper<SupplierProductions>().select("ID").lambda().eq(SupplierProductions::getCompanyId,StpLoginUserUtil.getLoginUser().getCompanyId()).in(SupplierProductions::getProductionCategoriesId,childCategoriesIdList)),SupplierProductions::getId);
                if(ObjectUtil.isNotEmpty(productionIds)) {
                    queryWrapper.lambda().in(SupplierStocks::getStockProductionId,productionIds);
                }else{
                    return new Page<>();
                }
            }else{
                return new Page<>();
            }
        }
        //供应商
        if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getStockSupplier())) {
            queryWrapper.lambda().eq(SupplierStocks::getStockSupplier, supplierStocksPageParam.getStockSupplier());
        }
//        queryWrapper.lambda().gt(SupplierStocks::getStockStock,0);//只对大于0的库存明细进行处理
        //汇总
        if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getIsHavingByProduction()) && supplierStocksPageParam.getIsHavingByProduction()){
            String sqlString = "STOCK_PRODUCTION_ID,SUM(STOCK_STOCK) AS STOCK_STOCK,AVG(STOCK_PRICE_PROCURE) AS STOCK_PRICE_PROCURE,SUM(STOCK_AMOUNT) AS STOCK_AMOUNT";
            String groupString = "STOCK_PRODUCTION_ID";
            if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getIsHavingByStore()) && supplierStocksPageParam.getIsHavingByStore()) {
                sqlString = sqlString + ", STOCK_STORE_ID";
                groupString = groupString + ", STOCK_STORE_ID";
            }
            if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getIsHavingByStorage()) && supplierStocksPageParam.getIsHavingByStorage()) {
                sqlString = sqlString + ", STOCK_STORAGE_ID";
                groupString = groupString + ", STOCK_STORAGE_ID";
            }
            if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getIsHavingByStoreLocation()) && supplierStocksPageParam.getIsHavingByStoreLocation()) {
                sqlString = sqlString + ", STOCK_STORE_LOCATION";
                groupString = groupString + ", STOCK_STORE_LOCATION";
            }
            if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getIsHavingByProductionBatch()) && supplierStocksPageParam.getIsHavingByProductionBatch()) {
                sqlString = sqlString + ", STOCK_BATCH";
                groupString = groupString + ", STOCK_BATCH";
            }
            if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getIsHavingByDateManufacture()) && supplierStocksPageParam.getIsHavingByDateManufacture()) {
                sqlString = sqlString + ", STOCK_DATE_MANUFACTURE";
                groupString = groupString + ", STOCK_DATE_MANUFACTURE";
            }
            if(ObjectUtil.isNotEmpty(supplierStocksPageParam.getIsHavingBySupplier()) && supplierStocksPageParam.getIsHavingBySupplier()) {
                sqlString = sqlString + ", STOCK_SUPPLIER";
                groupString = groupString + ", STOCK_SUPPLIER";
            }
            queryWrapper.select(sqlString);
            queryWrapper.groupBy(groupString);
        }

        //数据归属
        queryWrapper.lambda().eq(SupplierStocks::getCompanyId, StpLoginUserUtil.getLoginUser().getCompanyId());
        //库存等于零的不要了
        if(ObjectUtil.isEmpty(supplierStocksPageParam.getIsShowZero()) || !supplierStocksPageParam.getIsShowZero()) {
            queryWrapper.lambda().ne(SupplierStocks::getStockStock, 0);
        }
        if(ObjectUtil.isAllNotEmpty(supplierStocksPageParam.getSortField(), supplierStocksPageParam.getSortOrder())) {
            CommonSortOrderEnum.validate(supplierStocksPageParam.getSortOrder());
            queryWrapper.orderBy(true, supplierStocksPageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
                    StrUtil.toUnderlineCase(supplierStocksPageParam.getSortField()));
        } else {
            queryWrapper.lambda().orderByAsc(SupplierStocks::getStockProductionId);
        }

        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add(SupplierStocksAddParam supplierStocksAddParam) {
        SupplierStocks supplierStocks = BeanUtil.toBean(supplierStocksAddParam, SupplierStocks.class);
        //数据归属
        supplierStocks.setCompanyId(StpLoginUserUtil.getLoginUser().getCompanyId());
        this.save(supplierStocks);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void edit(SupplierStocksEditParam supplierStocksEditParam) {
        SupplierStocks supplierStocks = this.queryEntity(supplierStocksEditParam.getId());
        BeanUtil.copyProperties(supplierStocksEditParam, supplierStocks);
        this.updateById(supplierStocks);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(List<SupplierStocksIdParam> supplierStocksIdParamList) {
        // 执行删除
        this.removeByIds(CollStreamUtil.toList(supplierStocksIdParamList, SupplierStocksIdParam::getId));
    }

    @Override
    public SupplierStocks detail(SupplierStocksIdParam supplierStocksIdParam) {
        return this.queryEntity(supplierStocksIdParam.getId());
    }

    @Override
    public SupplierStocks queryEntity(String id) {
        SupplierStocks supplierStocks = this.getById(id);
        if(ObjectUtil.isEmpty(supplierStocks)) {
            throw new CommonException("库存明细不存在，id值为：{}", id);
        }
        return supplierStocks;
    }

    @Override
    public void exportStock(SupplierStocksExportParam supplierStocksExportParam, HttpServletResponse response) throws IOException {
        File tempFile = null;
        try {
            QueryWrapper<SupplierStocks> queryWrapper = new QueryWrapper<SupplierStocks>().checkSqlInjection();
            //如果是勾选的记录
            if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getIds())) {
                if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getIsHavingByProduction()) && supplierStocksExportParam.getIsHavingByProduction()){
//                    queryWrapper.lambda().in(SupplierStocks::getStockProductionId, supplierStocksExportParam.getStockProductionIds().split(","));
                }else{
                    queryWrapper.lambda().in(SupplierStocks::getId, supplierStocksExportParam.getIds().split(","));
                }
            }

            //门店或仓库ID
            if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getStockStoreId())) {
                queryWrapper.lambda().and(i -> i.eq(SupplierStocks::getStockStoreId, supplierStocksExportParam.getStockStoreId())
                        .or().eq(SupplierStocks::getStockStorageId, supplierStocksExportParam.getStockStoreId()));
            }
            //产品名称，拼音，条码，编号
            if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getStockProductionSearchKey())) {
                List<String> ids = CollStreamUtil.toList(supplierProductionsService.list(new QueryWrapper<SupplierProductions>().select("ID").lambda().eq(SupplierProductions::getCompanyId,StpLoginUserUtil.getLoginUser().getCompanyId()).and(i->i.like(SupplierProductions::getProductionName,supplierStocksExportParam.getStockProductionSearchKey())
                        .or().like(SupplierProductions::getProductionPinyincode,supplierStocksExportParam.getStockProductionSearchKey())
                        .or().like(SupplierProductions::getProductionCode,supplierStocksExportParam.getStockProductionSearchKey())
                        .or().like(SupplierProductions::getProductionBarcode,supplierStocksExportParam.getStockProductionSearchKey()))), SupplierProductions::getId);
                if(ObjectUtil.isNotEmpty(ids)) {
                    queryWrapper.lambda().in(SupplierStocks::getStockProductionId,ids);
                }else{
                    throw new CommonException("没有符合条件的数据可导出");
                }
            }
            //分类及子分类
            if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getStockProductionCategories())) {
                List<String> childCategoriesIdList = CollStreamUtil.toList(supplierCategoriesService.getChildListById(supplierCategoriesService.getAllCategoriesList(),supplierStocksExportParam.getStockProductionCategories(),true), SupplierCategories::getId);
                if(ObjectUtil.isNotEmpty(childCategoriesIdList)) {
                    List<String> productionIds = CollStreamUtil.toList(supplierProductionsService.list(new QueryWrapper<SupplierProductions>().select("ID").lambda().eq(SupplierProductions::getCompanyId,StpLoginUserUtil.getLoginUser().getCompanyId()).in(SupplierProductions::getProductionCategoriesId,childCategoriesIdList)),SupplierProductions::getId);
                    if(ObjectUtil.isNotEmpty(productionIds)) {
                        queryWrapper.lambda().in(SupplierStocks::getStockProductionId,productionIds);
                    }else{
                        throw new CommonException("没有符合条件的数据可导出");
                    }
                }
            }
            //供应商
            if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getStockSupplier())) {
                queryWrapper.lambda().eq(SupplierStocks::getStockSupplier, supplierStocksExportParam.getStockSupplier());
            }
            queryWrapper.lambda().gt(SupplierStocks::getStockStock,0);//只对大于0的库存明细进行处理
            List<String> showColNames = new ArrayList<>();
            showColNames.add("stockProductionCode");
            showColNames.add("stockProductionBarcode");
            showColNames.add("stockProductionName");
            showColNames.add("stockProductionSpec");
            showColNames.add("stockProductionUnit");
            showColNames.add("stockPriceProcure");
            showColNames.add("stockPriceProcureLast");
            showColNames.add("stockStock");
            showColNames.add("stockAmount");
            showColNames.add("stockProductionUnitAuxiliary");
            showColNames.add("stockStoreIdName");
            showColNames.add("stockStorageIdName");
            showColNames.add("stockStoreLocationName");
            showColNames.add("stockBatch");
            showColNames.add("stockDateManufacture");
            showColNames.add("stockSupplierName");
            if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getIsHavingByProduction()) && supplierStocksExportParam.getIsHavingByProduction()){
                String sqlString = "STOCK_PRODUCTION_ID,SUM(STOCK_STOCK) AS STOCK_STOCK,AVG(STOCK_PRICE_PROCURE) AS STOCK_PRICE_PROCURE,SUM(STOCK_AMOUNT) AS STOCK_AMOUNT";
                String groupString = "STOCK_PRODUCTION_ID";
                showColNames = new ArrayList<>();
                showColNames.add("stockProductionCode");
                showColNames.add("stockProductionBarcode");
                showColNames.add("stockProductionName");
                showColNames.add("stockProductionSpec");
                showColNames.add("stockProductionUnit");
                showColNames.add("stockPriceProcure");
                showColNames.add("stockStock");
                showColNames.add("stockAmount");
                showColNames.add("stockProductionUnitAuxiliary");

                if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getIsHavingByStore()) && supplierStocksExportParam.getIsHavingByStore()) {
                    sqlString = sqlString + ", STOCK_STORE_ID";
                    groupString = groupString + ", STOCK_STORE_ID";
                    showColNames.add("stockStoreIdName");
                }
                if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getIsHavingByStorage()) && supplierStocksExportParam.getIsHavingByStorage()) {
                    sqlString = sqlString + ", STOCK_STORAGE_ID";
                    groupString = groupString + ", STOCK_STORAGE_ID";
                    showColNames.add("stockStorageIdName");
                }
                if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getIsHavingByStoreLocation()) && supplierStocksExportParam.getIsHavingByStoreLocation()) {
                    sqlString = sqlString + ", STOCK_STORE_LOCATION";
                    groupString = groupString + ", STOCK_STORE_LOCATION";
                    showColNames.add("stockStoreLocationName");
                }
                if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getIsHavingByProductionBatch()) && supplierStocksExportParam.getIsHavingByProductionBatch()) {
                    sqlString = sqlString + ", STOCK_BATCH";
                    groupString = groupString + ", STOCK_BATCH";
                    showColNames.add("stockBatch");
                }
                if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getIsHavingByDateManufacture()) && supplierStocksExportParam.getIsHavingByDateManufacture()) {
                    sqlString = sqlString + ", STOCK_DATE_MANUFACTURE";
                    groupString = groupString + ", STOCK_DATE_MANUFACTURE";
                    showColNames.add("stockDateManufacture");
                }
                if(ObjectUtil.isNotEmpty(supplierStocksExportParam.getIsHavingBySupplier()) && supplierStocksExportParam.getIsHavingBySupplier()) {
                    sqlString = sqlString + ", STOCK_SUPPLIER";
                    groupString = groupString + ", STOCK_SUPPLIER";
                    showColNames.add("stockSupplierName");
                }
                queryWrapper.select(sqlString);
                queryWrapper.groupBy(groupString);
            }
            //数据归属
            queryWrapper.lambda().eq(SupplierStocks::getCompanyId, StpLoginUserUtil.getLoginUser().getCompanyId());

            if(ObjectUtil.isAllNotEmpty(supplierStocksExportParam.getSortField(), supplierStocksExportParam.getSortOrder())) {
                CommonSortOrderEnum.validate(supplierStocksExportParam.getSortOrder());
                queryWrapper.orderBy(true, supplierStocksExportParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
                        StrUtil.toUnderlineCase(supplierStocksExportParam.getSortField()));
            } else {
                queryWrapper.lambda().orderByAsc(SupplierStocks::getStockProductionId);
            }

            String fileName = (ObjectUtil.isNotEmpty(supplierStocksExportParam.getIsHavingByProduction()) && supplierStocksExportParam.getIsHavingByProduction()) ? "库存明细(汇总).xlsx" : "库存明细.xlsx";
            List<SupplierStocks> supplierStocksList = this.list(queryWrapper);
            if(ObjectUtil.isEmpty(supplierStocksList) || supplierStocksList.size()== 0) {
                throw new CommonException("没有符合条件的数据可导出");
            }
            transService.transBatch(supplierStocksList);
            supplierStocksList = CollectionUtil.sort(supplierStocksList, Comparator.comparing(SupplierStocks::getStockProductionId));
            List<SupplierStocksExportResult> supplierStocksExportResults = supplierStocksList.stream()
                    .map(supplierStocks -> {
                        if(ObjectUtil.isNotEmpty(supplierStocks.getStockProductionUnitAuxiliary())) {
                            List<JSONObject> auxiliaryList = (List<JSONObject>) JSON.parse(supplierStocks.getStockProductionUnitAuxiliary());
                            AtomicReference<String> unitAuxiliary = new AtomicReference<>("");
                            for(JSONObject auxiliary : auxiliaryList){
                                if(supplierStocks.getStockStock().doubleValue() / Double.parseDouble(auxiliary.get("conversion").toString()) > 1) {
                                    unitAuxiliary.set(new StringBuilder().append(unitAuxiliary.get()).append( (int) (supplierStocks.getStockStock().doubleValue() / Double.parseDouble(auxiliary.get("conversion").toString()))).append(auxiliary.get("unit")).append( (int) (supplierStocks.getStockStock().doubleValue() % Double.parseDouble(auxiliary.get("conversion").toString()))).append(supplierStocks.getStockProductionUnit()).append("；").toString());
                                }
                            }
                            supplierStocks.setStockProductionUnitAuxiliary(String.valueOf(unitAuxiliary));
                        }
                        SupplierStocksExportResult supplierStocksExportResult = new SupplierStocksExportResult();
                        BeanUtil.copyProperties(supplierStocks, supplierStocksExportResult);
                        if(ObjectUtil.isNotEmpty(supplierStocks.getStockDateManufacture())){
                            supplierStocksExportResult.setStockDateManufacture(dateFormat.format(supplierStocks.getStockDateManufacture()));
                        }
                        return supplierStocksExportResult;
                    }).collect(Collectors.toList());
            // 创建临时文件
            tempFile = FileUtil.file(FileUtil.getTmpDir() + FileUtil.FILE_SEPARATOR + fileName);
            // 头的策略
            WriteCellStyle headWriteCellStyle = new WriteCellStyle();
            WriteFont headWriteFont = new WriteFont();
            headWriteFont.setFontHeightInPoints((short) 14);
            headWriteCellStyle.setWriteFont(headWriteFont);
            // 水平垂直居中
            headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
            headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

            // 内容的策略
            WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
            // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
            contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
            // 内容背景白色
            contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
            WriteFont contentWriteFont = new WriteFont();

            // 内容字体大小
            contentWriteFont.setFontHeightInPoints((short) 10);
            contentWriteCellStyle.setWriteFont(contentWriteFont);

            //设置边框样式，细实线
            contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
            contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
            contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
            contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);

            // 水平垂直居中
            contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
            contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

            // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
            HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle,
                    contentWriteCellStyle);

            // 写excel
            EasyExcel.write(tempFile.getPath(),SupplierStocksExportResult.class)
                    //自定义需要列
                    .includeColumnFieldNames(showColNames)
                    // 自定义样式
                    .registerWriteHandler(horizontalCellStyleStrategy)
                    // 自动列宽
                    .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                    // 设置第一行字体
                    .registerWriteHandler(new CellWriteHandler() {
                        @Override
                        public void afterCellDispose(CellWriteHandlerContext context) {
                            WriteCellData<?> cellData = context.getFirstCellData();
                            WriteCellStyle writeCellStyle = cellData.getOrCreateStyle();
                            Integer rowIndex = context.getRowIndex();
                            if(rowIndex == 0) {
                                WriteFont headWriteFont = new WriteFont();
                                headWriteFont.setFontName("宋体");
                                headWriteFont.setBold(true);
                                headWriteFont.setFontHeightInPoints((short) 11);
                                writeCellStyle.setWriteFont(headWriteFont);
                            }
                        }
                    })
                    // 设置表头行高
                    .registerWriteHandler(new AbstractRowHeightStyleStrategy() {
                        @Override
                        protected void setHeadColumnHeight(Row row, int relativeRowIndex) {
                            if(relativeRowIndex == 0) {
                                // 表头第一行
                                row.setHeightInPoints(20);
                            } else {
                                // 表头其他行
                                row.setHeightInPoints(20);
                            }
                        }
                        @Override
                        protected void setContentColumnHeight(Row row, int relativeRowIndex) {
                            // 内容行
                            row.setHeightInPoints(18);
                        }
                    })
                    .sheet("库存明细")
                    .doWrite(supplierStocksExportResults);
            CommonDownloadUtil.download(tempFile, response);
        } catch (Exception e) {
            log.error(">>> 库存明细导出异常：", e);
            CommonResponseUtil.renderError(response, "导出失败");
        } finally {
            FileUtil.del(tempFile);
        }

    }
    @Override
    public Page<SupplierStocks> stocksBySupplierPage(SupplierProductionsPageParam supplierProductionsPageParam) {
        QueryWrapper<SupplierStocks> queryWrapper = new QueryWrapper<SupplierStocks>().checkSqlInjection();
        if(ObjectUtil.isNotEmpty(supplierProductionsPageParam.getProductionSupplier())){
            queryWrapper.lambda().eq(SupplierStocks::getStockSupplier,supplierProductionsPageParam.getProductionSupplier());
        }
        if(ObjectUtil.isNotEmpty(supplierProductionsPageParam.getLocationStorage())){
            queryWrapper.lambda().eq(SupplierStocks::getStockStorageId,supplierProductionsPageParam.getLocationStorage());
        }
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }
}
